package com.cloud.registery.controller;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class RegisteryController{

	private static ConcurrentMap<String ,String> serverList=new ConcurrentHashMap<String, String>();
	@PostMapping("regist")
	public String regist(@RequestBody Map<?, ?> param) {
		String appName=param.get("appName").toString();
		String serverUrl=param.get("serverUrl").toString();
		System.out.println("["+appName+"]"+serverUrl);
		serverList.put(appName, serverUrl);
		return "OK";
	}
	@GetMapping("fetchAll")
	public Map<String ,String> fetchAll() {
		return serverList;
	}
	
	@GetMapping("fetch")
	public String fetch(String appName) {
		return serverList.get(appName);
	}

}
